#pragma once
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>

#include "Result.h"

using namespace std;
class Course
{
protected:
	string courseName;
	int year;
	vector<Result> v;
public:

#pragma region Constructor/Destructor
	Course()
	{
		courseName = "";
		year = -1;
	}

	Course(string courseName, int year)
	{
		this->courseName = courseName;
		this->year = year;
	}

	~Course(){}
#pragma endregion

	void addResult(Result r)
	{
		v.push_back(r);
	}

	void read()
	{
		string s;
		cout << "Course name: ";
		getline(cin, courseName);
		cout << "Course year: ";
		getline(cin, s);
		istringstream iss(s);
		iss >> year;
	}

	//Data format Student=(Kalle,Anka,1991)
	//Course=(courseName,Year)
	//Result=(testName,grade)
	//Result=(testName,grade)
	//Course=(courseName,Year)
	friend ostream& operator<<(ostream &out, const Course &c)
	{
		out << "(";
		out << c.courseName << ",";
		out << c.year << ")";
		return out;
	}

	friend istream& operator>>(istream &in, Course &c)
	{
		string str;
		getline(in, str, '(');
		getline(in, c.courseName, ',');
		getline(in, str, ')');
		istringstream iss(str);
		iss >> c.year;
		return in;
	}

	string printResults()
	{
		ostringstream oss;
		for (auto r : v)
		{
			oss << "Result=" << r << endl;
		}
		return oss.str();
	}

	int getYear(){ return year; }

	virtual void print()
	{
		cout << "Coursename: " << courseName << ", Course year: " << year;
	}
};

